import { pageApi } from '/@/api/business/flowable/page'
import { ref } from "vue";
import { message } from "ant-design-vue";

export function useModelingPageApi(loading) {
  const pageInfo = ref()
  const pageList = ref([])

  async function getPage(pageId) {
    try {
      // loading && (loading.value = true)
      let temp = await pageApi.getPage(pageId)
      pageInfo.value = temp.data
    } catch (e) {
      console.error(e)
      message.error(e?.message || '查询失败')
    } finally {
      // loading && (loading.value = false)
    }
  }

  async function findPage(param) {
    try {
      // loading && (loading.value = true)
      let temp = await pageApi.findPage(param)
      pageInfo.value = temp.data
    } catch (e) {
      console.error(e)
      message.error(e?.message || '查询失败')
    } finally {
      // loading && (loading.value = false)
    }
  }

  async function findModulePages(param) {
    try {
      // loading && (loading.value = true)
      let temp = await pageApi.findModulePages(param)
      pageList.value = temp.data
    } catch (e) {
      console.error(e)
      message.error(e?.message || '查询失败')
    } finally {
      // loading && (loading.value = false)
    }
  }

  async function bindPage(param) {
    try {
      // loading && (loading.value = true)
      await pageApi.bindPage(param)
      message.success('绑定成功')
    } catch (e) {
      console.error(e)
      message.error(e?.message || '绑定失败')
    } finally {
      // loading && (loading.value = false)
    }
  }

  async function unbindPage(param) {
    try {
      // loading && (loading.value = true)
      await pageApi.unbindPage(param)
      message.success('解绑成功')
    } catch (e) {
      console.error(e)
      message.error(e?.message || '解绑失败')
    } finally {
      // loading && (loading.value = false)
    }
  }

  return {
    pageInfo, getPage, findPage, bindPage, unbindPage,
    pageList, findModulePages,
  }
} 